package tmproject.hlhj.fhp.tmvote.module

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.tmvote.beans.BaseBean
import tmproject.hlhj.fhp.tmvote.beans.PayBean
import tmproject.hlhj.fhp.tmvote.beans.PayWaysBean
import tmproject.hlhj.fhp.tmvote.network.Apis
import tmproject.hlhj.fhp.tmvote.network.BaseObersever
import tmproject.hlhj.fhp.tmvote.network.LoadingAction
import java.io.File

/**
 * Created by Never Fear   on 2018\8\7 0007.
Never More....
 */
class PayModule :BaseModule {
    var listener:OnPayListener?=null
    fun pay(user_id:String, competitor_name:String, phone:String, profile:String, activity_id:String,
            pay_way:String?, avatar: File, context: Context){
        Apis.signUp(user_id, competitor_name, phone, profile, activity_id, pay_way, avatar)
                ?.let {
                    it.doOnSubscribe(LoadingAction(context))
                            .subscribe(object :BaseObersever<Response<BaseBean>>(context){
                                override fun onRespSuccess(t: Response<BaseBean>) {
                                    listener?.onSignResult(t.body())
                                }
                            })
                }

    }
    fun getPayways(context: Context){
        Apis.getPayways()?.let {
          it.doOnSubscribe(LoadingAction(context))
                  .subscribe(object :BaseObersever<Response<PayWaysBean>>(context){
                      override fun onRespSuccess(t: Response<PayWaysBean>) {
                              listener?.onPaywaysRep(t.body())
                      }
                  })
        }
    }
    interface OnPayListener{
        fun onSignResult(baseBean: BaseBean)

        fun onPayResult(payBean: PayBean)

        fun onPaywaysRep(payWaysBean: PayWaysBean)
    }
}